package com.leo.ibatis.demo.service.impl;

import java.util.List;

import com.leo.ibatis.demo.base.Service;
import com.leo.ibatis.demo.criteria.InventoryCriteria;
import com.leo.ibatis.demo.dao.InventoryDao;
import com.leo.ibatis.demo.domain.Inventory;
import com.leo.ibatis.demo.service.InventoryService;

public class InventoryServiceImpl extends Service implements InventoryService {

	private InventoryDao inventoryDao;

	public void setInventoryDao(InventoryDao inventoryDao) {
		this.inventoryDao = inventoryDao;
	}

	public void insert(Inventory inventory) {
		inventoryDao.insert(inventory);
	}

	public int update(Inventory inventory) {
		int actualRowsAffected = 0;
		
		String itemid = inventory.getItemid();

		Inventory _oldInventory = inventoryDao.select(itemid);
		
		if (_oldInventory != null) {
			actualRowsAffected = inventoryDao.update(inventory);
		}
		
		return actualRowsAffected;
	}

	public int delete(String itemid) {
		int actualRowsAffected = 0;
		
		Inventory _oldInventory = inventoryDao.select(itemid);
		
		if (_oldInventory != null) {
			actualRowsAffected = inventoryDao.delete(itemid);
		}
		
		return actualRowsAffected;
	}
	
	public Inventory select(String itemid) {
		return inventoryDao.select(itemid);
	}

	public List<Inventory> list(InventoryCriteria inventoryCriteria) {
		return inventoryDao.list(inventoryCriteria);
	}
	
	public List<Inventory> listOnPage(InventoryCriteria inventoryCriteria) {
		return inventoryDao.listOnPage(inventoryCriteria);
	}

}
